package day_2022_12_to_3.year2023;

import java.util.HashSet;
import java.util.Set;

/**
 * @author haomin
 * @date 2023/04/09 10:29
 **/
public class Day4_9_Num2399 {
    class Solution {
        public boolean checkDistances(String s, int[] distance) {
            Set<Character> set = new HashSet<>();
            for(int i = 0; i < s.length(); ++i) {
                char c1 = s.charAt(i);
                if(!set.add(c1)) continue;
                if(i + distance[(int)c1 - 97] + 1 >= s.length()) return false;
                char c2 = s.charAt(i + distance[(int)c1 - 97] + 1);
                if(c1 != c2) return false;
            }
            return true;
        }
    }
}